var Channel = {
    id: "ChannelTable",
    seItem: null,
    table: null,
    layerIndex: -1
};
Channel.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', align: 'center', valign: 'middle', width: '50px'},
        {title: '渠道名称', field: 'channelname', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true},
        {title: '排序', field: 'num', align: 'center', valign: 'middle', sortable: true},
    ];
};
Channel.check = function () {
    var selected = $('#' + this.id).bootstrapTreeTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Channel.seItem = selected[0];
        return true;
    }
};
Channel.openAddChannel = function () {
    var index = layer.open({
        type: 2,
        title: '添加渠道',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channel/channel_add'
    });
    this.layerIndex = index;
};
Channel.openChannelDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '渠道详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/channel/channel_update/' + Channel.seItem.id
        });
        this.layerIndex = index;
    }
};

Channel.openMaxChannelauditLevel = function () {
    var index = layer.open({
        type: 2,
        title: '渠道详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channel/to_maxChannelauditLevel'
    });
    this.layerIndex = index;
};

Channel.delete = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/channel/delete", function () {
                Feng.success("删除成功!");
                Channel.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("channelId", Channel.seItem.id);
            ajax.start();
        };
        Feng.confirm("是否刪除该渠道?", operation);
    }
};
Channel.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Channel.table.refresh({query: queryData});
};
Channel.resetSearch = function () {
    $("#condition").val("");
    PayService.search();
};
$(function () {
    var defaultColunms = Channel.initColumn();
    var table = new BSTreeTable(Channel.id, "/channel/list", defaultColunms);
    table.setExpandColumn(2);
    table.setIdField("id");
    table.setCodeField("id");
    table.setParentCodeField("pid");
    table.setExpandAll(true);
    table.init();
    Channel.table = table;
});